<html>
<head>
   <meta name="description" content="easyui help you build your web page easily!">
        <title>Attendance</title>
        <link href="http://localhost/Eldercare/finalstyle.css" rel="stylesheet" type="text/css" media="all" />
        <script type="text/javascript" src="C:\xampp\htdocs\Eldercare\jquery\jquery-1.6.min.js"></script>
        <script type="text/javascript" src="C:\xampp\htdocs\Eldercare\jquery\jquery.easyui.min.js"></script>
        <script type="text/javascript" src="C:\xampp\htdocs\Eldercare\jquery\jquery.min.js"></script>
        <script src="http://localhost/Eldercare/jquery/demoad.js"></script>
        <script src="http://localhost/Eldercare/jquery/searchbox.js"></script>
<style type="text/css">
            body {
                background: #FFFFFF url("images/bg.png") repeat;
                background-attachment:fixed;
            }
			.button 
			{
        background-color:beige;
        cursor:pointer; }
		
		.btn
		{
		

			background-color:#FFF5EE;
			cursor:pointer;
		}
			.btn1
		{
			border-radius: 5px;
			box-shadow: #EEE6E6 3px 3px 3px; 
			border: 1px solid #892525;
			background-color:#F8F1D4;
			cursor:pointer;
		}
    }
        </style>
</head>
<body>
<?php
if(!empty($_SESSION["centreName"]))
{
	$centreName == $_SESSION["centreName"];

}
if(!empty($_SESSION["userType"]))
{
	$userType == $_SESSION["userType"];
}
$centreId = intval(isset($_POST['CentreSubmit']) ? $_POST['ddlCentre'] : '' );

include 'conn.php';
if($centreId==0)
{
	$where ="";
}
else
{
	$where = "AND ar.CentreId=$centreId";
}
if($userType=="System Admin")
{
		$result = mysql_query("SELECT ar.NRIC, c.CustomerName, ar.SignInTimeStamp,  ar.SignOutTimeStamp
		FROM attendancerecord ar, client c
		WHERE DATE( SignInTimeStamp ) = CURDATE( ) 
		AND ar.NRIC = c.NRIC $where");

		echo "<form action='".$_SERVER['PHP_SELF']."' method='POST'><table class='tablereport' id='tblAttendance' border='0'  valign='top'><tr >
		<td name='NRIC'>
		<font face='Arial, Helvetica, sans-serif'>NRIC</font>
		</td>
		<td name='CustomerName'>
		<font face='Arial, Helvetica, sans-serif'>Name</font>
		</td>
		<td name='Date'>
		<font face='Arial, Helvetica, sans-serif'>Date</font>
		</td>
		<td name='TimeIn' >
		<font face='Arial, Helvetica, sans-serif'>Time In</font>
		</td>
		<td name='TimeOut'>
		<font face='Arial, Helvetica, sans-serif'>Time Out</font>
		</td>
		<td name='SignOut'>
		<font face='Arial, Helvetica, sans-serif'>Sign Out </font><form method='POST'><input type='submit' button class='btn' name='signoutall'value='Sign Out All' size='10' maxlength='9'/></form>
		</td>
		</tr>";
		$count=0;
		while($row = mysql_fetch_array($result))
		  {
		  echo"<tr>
		<td >
		<font face='Arial, Helvetica, sans-serif'>".$row['NRIC']."</font>
		</td >
		<td >
		<font face='Arial, Helvetica, sans-serif'>".$row['CustomerName']."</font>
		</td >
		<td >
		<font face='Arial, Helvetica, sans-serif'>".$today = date('j F, Y')."</font>
		</td>
		";
		 $signin = strtotime($row['SignInTimeStamp']);
		$signintime = date('H:i:s', $signin);
		echo"<td >
		<font face='Arial, Helvetica, sans-serif'>".$signintime."</font>
		</td>";
		if($row['SignOutTimeStamp']=='0000-00-00 00:00:00'|| $row['SignOutTimeStamp']==NULL)
				{echo "
				<td >
				<font face='Arial, Helvetica, sans-serif'></font>
				</td>
				<td style='text-align:center;vertical-align:middle'>
                                <form method='POST' >
		<button type='submit' name='btnSO' value='{$row['NRIC']}'>
              Sign Out
            </button></form>
				</td>";
		}
		else{ 
		$signout = strtotime($row['SignOutTimeStamp']);
		$signouttime = date('H:i:s', $signout);
		echo"
		<td >
		<font face='Arial, Helvetica, sans-serif'>".$signouttime."</font>
		</td>
		<td style='text-align:center;vertical-align:middle'>
		</td>
		";
		} echo"

		</tr>"
		;$count++;
		  }
		echo "</table></form>";

}
else
{
	$result = mysql_query("SELECT ar.NRIC, c.CustomerName, ar.SignInTimeStamp, ar.SignOutTimeStamp
FROM attendancerecord ar, client c
WHERE DATE( SignInTimeStamp ) = CURDATE( ) 
AND ar.NRIC = c.NRIC
AND ar.CentreId
IN (

SELECT CentreId
FROM centre
WHERE CentreName =  '$centreName'
)");

		echo "<form action='".$_SERVER['PHP_SELF']."' method='POST'><table class='tablereport' id='tblAttendance' border='0'  valign='top'><tr >
		<td name='NRIC'>
		<font face='Arial, Helvetica, sans-serif'>NRIC</font>
		</td>
		<td name='CustomerName'>
		<font face='Arial, Helvetica, sans-serif'>Name</font>
		</td>
		<td name='Date'>
		<font face='Arial, Helvetica, sans-serif'>Date</font>
		</td>
		<td name='TimeIn' >
		<font face='Arial, Helvetica, sans-serif'>Time In</font>
		</td>
		<td name='TimeOut'>
		<font face='Arial, Helvetica, sans-serif'>Time Out</font>
		</td>
		<td name='SignOut'>
		<font face='Arial, Helvetica, sans-serif'>Sign Out </font><form method='POST'><input type='submit' button class='btn' name='signoutall'value='Sign Out All' size='10' maxlength='9'/></form>
		</td>
		</tr>";
		$count=0;
		while($row = mysql_fetch_array($result))
		  {
		  echo"<tr>
		<td >
		<font face='Arial, Helvetica, sans-serif'>".$row['NRIC']."</font>
		</td >
		<td >
		<font face='Arial, Helvetica, sans-serif'>".$row['CustomerName']."</font>
		</td >
		<td >
		<font face='Arial, Helvetica, sans-serif'>".$today = date('j F, Y')."</font>
		</td>
		";
		 $signin = strtotime($row['SignInTimeStamp']);
		$signintime = date('H:i:s', $signin);
		echo"<td >
		<font face='Arial, Helvetica, sans-serif'>".$signintime."</font>
		</td>";
		if($row['SignOutTimeStamp']=='0000-00-00 00:00:00'|| $row['SignOutTimeStamp']==NULL)
				{echo "
				<td >
				<font face='Arial, Helvetica, sans-serif'></font>
				</td>
				<td style='text-align:center;vertical-align:middle'><form method='POST'>
		<button type='submit' name='btnSO' value='{$row['NRIC']}'>
              Sign Out
            </button></form>
				</td>";
		}
		else{ 
		$signout = strtotime($row['SignOutTimeStamp']);
		$signouttime = date('H:i:s', $signout);
		echo"
		<td >
		<font face='Arial, Helvetica, sans-serif'>".$signouttime."</font>
		</td>
		<td style='text-align:center;vertical-align:middle'>
		</td>
		";
		} echo"

		</tr>"
		;$count++;
		  }
		echo "</table></form>";

}

?>
</body>
</html>